package com.icid.store.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.icid.store.business.delegate.ImageDelegate;
	import com.icid.store.event.GetImageListEvent;
	import com.icid.store.model.ImageModelLocator;
	import com.icid.store.vo.ImageVO;
	
	import mx.rpc.IResponder;

	public class GetImageListCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:ImageDelegate;
		private var getImageListEvent:GetImageListEvent;
		private var imageModel:ImageModelLocator = ImageModelLocator.getInstance();
		public function GetImageListCommand()
		{
			super();
			delegate = new ImageDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			getImageListEvent = GetImageListEvent(event);
			delegate.read(getImageListEvent.iid);
		}
		
		override public function result(data:Object):void
		{
//			trace(data.result);
			imageModel.imageList.removeAll();
			for(var i:int=0;i<data.result.length;i++)
			{
				var imageVO:ImageVO = new ImageVO();
				
				imageVO.description = data.result[i].description;
				imageVO.id = data.result[i].id;
				imageVO.time = data.result[i].time;
				imageVO.title = data.result[i].title;
				imageVO.url = data.result[i].url;
				
				imageModel.imageList.addItem(imageVO);
			}
			imageModel.imageList.refresh();
		}
		
	}
}